package bean;

import java.util.List;

public class Page {
    private int size;
    public static final int DEFAULT_SIZE = 10;
    private int total;
    private int serial;
    public static final int DEFAULT_SERIAL = 1;
    private int recordsCount;
    private List<Contact> records;

    public int getRecordsCount() {
        return recordsCount;
    }

    public void setRecordsCount(int recordsCount) {
        this.recordsCount = recordsCount;
        setTotal(recordsCount);
    }

    public int getTotal() {
        return total;
    }

    private void setTotal(int recordsCount) {
        if (recordsCount > 0) {
            int quotient = recordsCount / size;
            this.total = recordsCount % size == 0 ? quotient : quotient + 1;
        } else {
            total = 1;
        }
    }

    public int getSerial() {
        return serial;
    }

    public void setSerial(int serial) {
        if (serial < DEFAULT_SERIAL) {
            this.serial = DEFAULT_SERIAL;
        } else if (serial > total) {
            this.serial = total;
        } else {
            this.serial = serial;
        }
    }

    public int getSize() {
        return size;
    }

    public List<Contact> getRecords() {
        return records;
    }

    public void setRecords(List<Contact> records) {
        this.records = records;
    }

    public Page() {
        size = DEFAULT_SIZE;
    }

    public Page(int pageSize) {
        this.size = pageSize;
    }
}
